package middleware

import (
	"github.com/PhlexTheCharr/gofurry-cloud-service/common"
	"github.com/PhlexTheCharr/gofurry-cloud-service/roof/env"
	"github.com/gofiber/fiber/v2"
	"strings"
)

/*
 * @Desc: 基于配置文件token的鉴权
 * @author: 慵狼小洛
 * @version: v1.0.0
 */

func ApiTokenMiddleware() fiber.Handler {
	apiToken := env.GetServerConfig().Api.Token
	return func(c *fiber.Ctx) (err error) {
		authorization := strings.TrimSpace(c.Get("Authorization"))
		if authorization != apiToken {
			return common.NewResponse(c).Error("API Token错误")
		}
		return c.Next()
	}
}
